﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class Diamond
    {
        public Diamond()
        {
            int T = GetConsole.GetInt();
            while (T-- > 0)
            {
                int N = GetConsole.GetInt();
                int[,] diamond = new int[2*N-1,N];


                for (int i = 0; i < N; i++)
                {
                    for (int j = 0; j < i + 1; j++)
                    {
                        diamond[i, j] = GetConsole.GetInt();
                    }
                }
                for(int i = 0; i < N - 1; i++)
                {
                    for (int j = i + 1; j < N; j++)
                    {
                        diamond[i + N, j] = GetConsole.GetInt();
                    }
                }
                for (int i = 1; i < 2 * N - 1; i++)
                {
                    diamond[i, 0] += diamond[i - 1, 0];
                    for (int j = 1; j < N; j++)
                    {
                        int leftValue = diamond[i, j] + diamond[i - 1, j - 1];
                        int rightValue = diamond[i, j] + diamond[i - 1, j];
                        if (leftValue > rightValue)
                        { diamond[i, j] = leftValue; }
                        else
                        { diamond[i, j] = rightValue; }
                    }
                }
                Console.WriteLine(diamond[2 * N - 2, N - 1]);
            }
        }
    }
}
